package nuonuo.com.mytest;

import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.SeekBar;

/**
 * Created by n6 on 2016/10/25.
 */
public class SeekBarActivity extends AppCompatActivity {

    private FrameLayout fmLayout;
    private Handler handler = new Handler();
    private View view;
    private int width, height, marginLeft;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_seekbar);

        initViews();
        initData();

    }

    private void initData() {
        handler.post(new Runnable() {
            @Override
            public void run() {
                width = view.getWidth();
                height = view.getHeight();
                marginLeft = 0;
                creatSeekBars();
            }
        });
    }

    private void creatSeekBars() {
        for (int i = 0; i < 4; i++) {
            SeekBar sbar = new SeekBar(this);
            fmLayout.addView(sbar);
            FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(width / 4, height);
            lp.setMargins( ( i) * (width / 4), 0, 0, 0);
            Log.i("mtag",(marginLeft + (2 * i + 1) * (width / 9))+"---"+sbar.toString()+"---"+lp.toString());
            sbar.setLayoutParams(lp);
        }
        Log.i("mtag",fmLayout.getChildCount()+"");
    }

    private void initViews() {
        fmLayout = (FrameLayout) findViewById(R.id.fram_container);
        view = findViewById(R.id.view);
    }
}
